<template>
  <div>
    <PageTitle title="评论列表"></PageTitle>
    <el-table
      stripe
      :data="tableData"
    >
      <el-table-column
        prop="id"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="company"
        label="公司名称">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
      </el-table-column>
      <el-table-column
        prop="username"
        label="绑定账号">
      </el-table-column>
      <el-table-column
        prop="create_at"
        label="添加日期">
      </el-table-column>
      <el-table-column
        label="操作">
      <template slot-scope="scope">
        <router-link
          :to="'/firstTypeList/firstTypeDetail/' + scope.row.id + '/' + scope.row.company+'/'+scope.row.login_id"
          class="el-button el-button--text"
        >查看</router-link>
        <el-button @click.native="del(scope.row.id)" type="text">删除</el-button>
      </template>
      </el-table-column>
    </el-table>
    <div class='pagination-wrapper'>
      <el-pagination
          layout="prev, pager, next"
          @current-change="pageChange"
          :total="totalCount"
          :page-size="pageSize"
          :current-page="pageNum"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
  // import _ from 'lodash'
  import PageTitle from '@/components/pageTitle/PageTitle.vue'
  export default {
    name: 'FirstTypeList',
    components: {
      PageTitle
    },
    activated() {
      this._getList()
    },
    data() {
      return {
        tableData: [],
        pageNum: 1,
        pageSize: 10,
        totalCount: 0,
        status: '0'
      }
    },
    methods: {
      async _getList() {
        let { data: { data, code } } = await this.$axios({
          url: this.$api + '/v1/company/list',
          method: 'GET',
          params: {
            size: this.pageSize,
            current: this.pageNum
          }
        })
        if(code == 0) {
          this.tableData = data.items
          this.totalCount = data.page.totalCount
        }
      },
      changeState(id, state) {
        this.$confirm(`确认变更状态吗？`, '提示', {
          type: 'warning'
        }).then(async () => {
          this._changeState(id, state)
        })
      },
      del(id) {
        this.$confirm(`确认变更状态吗？`, '提示', {
          type: 'warning'
        }).then(() => {
          this._del(id)
        })
      },
      async _del(id) {
        let { data: { code, data } } = await this.$axios({
          url: this.$api + '/v1/company/strike',
          method: 'POST',
          data: {
            id
          }
        })
        if (code === 0) {
          this.$message.success(data)
          this._getList()
        }
      },
      handleClick(s) {
        this.status = s
        this.pageNum = 1
        this._getList()
      },
      pageChange(pageNum) {
        this.pageNum = pageNum
        this._getList()
      }
    },
  }
</script>

<style lang="scss">
  @import '@/assets/css/select-bar.scss';
  .el-button--text, .el-button--primary {
    text-decoration: none;
  }
  .pagination-wrapper {
    text-align: center;
    margin-top: 20px;
  }
</style>
